<template>
  <div>
    <!-- banner -->
    <div class="banner" :style="cover">
      <h1 class="banner-title">{{ photoAlbumName }}</h1>
    </div>
    <!-- 相册列表 -->
    <v-card class="blog-container">
      <div class="photo-wrap">
        <img
            v-for="(item, index) of photoList"
            class="photo"
            :key="index"
            :src="item"
            @click="preview(index)"
        />
      </div>
      <!-- 无限加载 -->
      <infinite-loading @infinite="infiniteHandler">
        <div slot="no-more"/>
        <div slot="no-results"/>
      </infinite-loading>
    </v-card>
  </div>
</template>

<script>
export default {
  data: function () {
    return {
      photoAlbumName: "",
      photoAlbumCover: "",
      photoList: [],
      current: 1,
      size: 10
    };
  },
  methods: {
    preview(index) {
      this.$imagePreview({
        images: this.photoList,
        index: index
      });
    },
    infiniteHandler($state) {
      this.axios
          .get("/api/photo/blogListPhotos", {
            params: {
              current: this.current,
              size: this.size,
              albumId: this.$route.params.albumId
            }
          })
          .then(res => {
            this.photoAlbumCover = res.data.data.album.albumCover;
            this.photoAlbumName = res.data.data.album.albumName;
            if (this.photoList.length < res.data.data.count) {
              this.current++;
              res.data.data.data.forEach(item => {
                this.photoList.push(item.photoSrc);
              })
              $state.loaded();
            } else {
              $state.complete();
            }
          });
    }
  },
  computed: {
    cover() {
      return (
          "background: url(" +
          this.photoAlbumCover +
          ") center center / cover no-repeat"
      );
    }
  }
};
</script>

<style scoped>
.photo-wrap {
  display: flex;
  flex-wrap: wrap;
}

.photo {
  margin: 3px;
  cursor: pointer;
  flex-grow: 1;
  object-fit: cover;
  height: 200px;
}

.photo-wrap::after {
  content: "";
  display: block;
  flex-grow: 9999;
}

@media (max-width: 759px) {
  .photo {
    width: 100%;
  }
}
</style>
